﻿@model EF_WebApplication1.Models.UserModel

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>AddUser</title>
</head>
<body>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/jqueryajax")

    <script type="text/javascript">

        function beginFunction() {
            $("#btnCreate").hide();
        }
        function afterSuccess(data) {

            $("#btnCreate").show();
            console.log(data);
            if (data) {
                
            }
            //alert(data);
        }
    </script>
    <div id="result">

    </div>

    <div id="loading" style="display:none" data-url="@Url.Action("AddUser","Home")">
        保存中，请稍等...
    </div>

    @using (Ajax.BeginForm("AddUser", "Home", new AjaxOptions() { Confirm = "是否确认要保存数据吗？", HttpMethod = "Post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "result",OnBegin = "beginFunction", OnSuccess = "afterSuccess", LoadingElementId = "loading" }))
    {
        <div class="form-horizontal">
            <h4>UserModel</h4>
            <hr />
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Pwd1, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.PasswordFor(model => model.Pwd1, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Pwd1, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Pwd2, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.PasswordFor(model => model.Pwd2, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Pwd2, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Age, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.Age, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Age, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Create" id="btnCreate" class="btn btn-default" />
                </div>
            </div>
        </div>
    }
    <div>
        @Html.ActionLink("Back to List", "Index")
    </div>
</body>
</html>
